<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8" />
    <style>
      * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
      }
      body {
        display: flex;
        align-items: center;
        justify-content: center;
        height: 100vh;
        background: linear-gradient(-135deg, #c850c0, #4158d0);
      }
      .main {
        width: 480px;
        background-color: rgb(252, 247, 255);
        padding: 32px;
        box-shadow: 0 0 16px rgb(24, 220, 255);
        border-radius: 8px;
      }
      .data {
        height: 52px;
        width: 100%;
        position: relative;
        bottom: -6px;
      }
      .data input {
        height: 100%;
        width: 100%;
        border: none;
        outline: none;
        font-size: 20px;
        background-color: transparent;
        border-bottom: 2px solid rgb(255, 255, 255);
      }
      .data input:focus ~ label,
      .data input:valid ~ label {
        bottom: 46px;
        font-size: 26px;
        color: rgb(205, 142, 224);
      }
      .data label {
        position: absolute;
        left: 0;
        bottom: 10px;
        font-size: 18px;
        color: rgb(155, 149, 149);
        pointer-events: none;
        user-select: none;
        transition: 0.4s;
      }
      .data .underline {
        position: absolute;
        bottom: 0;
        width: 100%;
        height: 2px;
        background-color: rgb(231, 160, 238);
      }
      .data input:focus ~ .underline,
      .data input:valid ~ .underline {
        position: absolute;
        bottom: 0;
        content: "";
        height: 4px;
        border-radius: 6px;
        background-color: rgb(133, 179, 248);
        animation: input 0.4s forwards ease-in-out;
      }
      @keyframes input {
        from {
          width: 0%;
        }
        to {
          width: 100%;
        }
      }
    </style>
    <title>Input 输入动画</title>
  </head>
  <body>
    <div class="main">
      <div class="data">
        <input type="text" required />
        <div class="underline"></div>
        <label>name</label>
      </div>
    </div>
  </body>
</html>
